package com.flextribe.util {
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.text.TextField;

	public class TextFieldUtils {

		public static function getBoundingRectangle(tf:TextField, search:String):Rectangle {

			var leftTarget:Point;
			var rightTarget:Point;
			var index:Number = tf.text.indexOf(search);

			/*
			 * The following lines are a workaround for the 
			 * following issue: http://bugs.adobe.com/jira/browse/FP-1430
			 */
			tf.width;
			tf.height;

			var rect:Rectangle = tf.getCharBoundaries(index);
			leftTarget = new Point(rect.x, rect.y);

			var rect2:Rectangle = tf.getCharBoundaries(index + search.length - 1);
			rightTarget = new Point(rect2.x + rect2.width, rect2.y);

			return new Rectangle(leftTarget.x, leftTarget.y, rightTarget.x - leftTarget.x, rightTarget.y - leftTarget.y);
		}
	}
}

